home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / irsim / fio.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  2KB  |  93 lines

  1. /* 
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     ********************************************************************* 
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <defs.h>
  17.  
  18. extern    void    clearerr();
  19.  
  20.  
  21. /*
  22.  * My version of fgets, fread, and fwrite.  These routines provide the same
  23.  * functionality as the stdio ones; taking care of restarting the operation
  24.  * upon an interrupt condition.  This is mostly for system V. 
  25.  */
  26.  
  27.  
  28. public char *fgetline( bp, len, fp )
  29.   char           *bp;
  30.   register int   len;
  31.   register FILE  *fp;
  32.   {
  33.     register char  *buff = bp;
  34.     register int  c;
  35.  
  36.     while( --len > 0 )
  37.       {
  38.       again :
  39.     c = getc( fp );
  40.     if( c == EOF )
  41.       {
  42.         if( feof( fp ) == 0 )
  43.           {
  44.         clearerr( fp );
  45.         goto again;
  46.           }
  47.         *buff = '\0';
  48.         return( NULL );
  49.       }
  50.     *buff++ = c;
  51.     if( c == '\n' )
  52.         break;
  53.       }
  54.     *buff = '\0';
  55.     return( bp );
  56.   }
  57.  
  58.  
  59. public int Fread( ptr, size, fp )
  60.   char  *ptr;
  61.   int   size;
  62.   FILE  *fp;
  63.   {
  64.     register int  ret;
  65.  
  66.   again :
  67.     ret = fread( ptr, 1, size, fp );
  68.     if( ret <= 0 and feof( fp ) == 0 )
  69.       {
  70.     clearerr( fp );
  71.     goto again;
  72.       }
  73.     return( ret );
  74.   }
  75.  
  76.  
  77. public int Fwrite( ptr, size, fp )
  78.   char  *ptr;
  79.   int   size;
  80.   FILE  *fp;
  81.   {
  82.     register int  ret;
  83.  
  84.   again :
  85.     ret = fwrite( ptr, 1, size, fp );
  86.     if( ret <= 0 and feof( fp ) == 0 )
  87.       {
  88.     clearerr( fp );
  89.     goto again;
  90.       }
  91.     return( ret );
  92.   }
  93.